-- pure_damage
-- Created by chengb Nov/13/2015
-- 技能: 单体，对目标施加纯伤害（不考虑加成等因素）
-- 目前支持如下配置： pure_damage(800, 200)：对目标造成800的魔法伤害，技能每提升1级，效果增加200。（最终结果还要除以1000）

return {
    apply = function(source, target, skillId, round, para, extra)
        local base  = para[1];
        local growth = para[2];
        local level = extra["level"] or 0; 
       
        -- 攻击方的魔力
        local magic = source:getMagic();
        
        -- 最终伤害
        local damage = math.modf(magic * (base + level * growth) / 1000);

        -- 增加命中动作
        SkillM.getSequence(target):hit(source, target, skillId);

        -- 伤害
        CombatM.receiveDamage(source, target, damage, skillId, extra);

        -- 如果是玩家，抛出攻击结果事件
        if source.type == OBJECT_TYPE_USER then
            EventMgr.fire(event.HERO_ATTACK_RESULT, { ["damage"] = damage, ["extra"] = extra});
        end
        
        -- 作用目标
        return { target, };
    end,

    parse = function(desc)
        local arr = string.explode(desc, ",");
        if (#arr == 1) then
            return { tonumber(arr[1]), };
        else
            local styleList = string.explode(arr[2], "+");
            if #styleList > 1 then
                return { tonumber(arr[1]), styleList, tonumber(arr[3]) };
            else
                return { tonumber(arr[1]), tonumber(arr[2]), tonumber(arr[3]) };
            end
        end
    end,

    -- 解析技能描述
    parseDesc = function(source, skillId, desc, para)
        local base   = para[1];
        local growth = para[2];
        local level  = SkillM.getSkillLevel(skillId);
              
        local magic = source:getMagic();
        
        -- 最终伤害
        local damage = math.modf(magic * (base + level * growth) / 1000);

        desc = string.gsub(desc, "{damage}", damage);

        return desc;
    end,
};
